<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML lang="UTF-8">
<HEAD>
	<META http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<META http-equiv="Content-Language" content="UTF-8" />
	<TITLE FCKLANG="DlgSyntaxHighLighterProperty">语法高亮代码属性</TITLE>
	<SCRIPT language="javascript" src="./dp.SyntaxHighlighter/Scripts/shCore.js"></SCRIPT>
	<SCRIPT language="javascript">
	var oEditor = window.parent.InnerDialogLoaded() ;
	var FCKBrowserInfo = oEditor.FCKBrowserInfo;
	var FCKLang = oEditor.FCKLang ;
	var FCKHighLighter = oEditor.FCKHighLighter ;

	var usingTag = "DIV";
	var usingFlag = "HighLighter";

	//var SCRIPT_PATH	  = FCKConfig.PluginsPath + "highlighter/dp.SyntaxHighlighter/Scripts/";
	var SCRIPT_PATH	  = "./dp.SyntaxHighlighter/Scripts/";
	var PREFIX 		  = "shBrush";
	var POSTFIX 	  = ".js";
	var TypeMapper = {
		"php"        : PREFIX + "Php" + POSTFIX ,
		"javascript" : PREFIX + "JScript" + POSTFIX ,
		"java" 		 : PREFIX + "Java" + POSTFIX ,
		"xml"  		 : PREFIX + "Xml" + POSTFIX ,
		"html"  	 : PREFIX + "Xml" + POSTFIX ,
		"c++"  		 : PREFIX + "Cpp" + POSTFIX ,
		"c#" 		 : PREFIX + "CSharp" + POSTFIX ,
		"css" 		 : PREFIX + "Css" + POSTFIX ,
		"delphi" 	 : PREFIX + "Delphi" + POSTFIX ,
		"python" 	 : PREFIX + "Python" + POSTFIX ,
		"ruby" 		 : PREFIX + "Ruby" + POSTFIX ,
		"sql" 		 : PREFIX + "Sql" + POSTFIX ,
		"vb" 		 : PREFIX + "Vb" + POSTFIX
	};

	window.onload = function () {
		// First of all, translate the dialog box texts
		oEditor.FCKLanguageManager.TranslatePage( document ) ;

		LoadSelected();

		// Show the "Ok" button.
		window.parent.SetOkButton( true ) ;

		document.getElementById("code").focus();
	}

	function Ok()
	{
		if(document.getElementById("codeType").value.length == 0)
		{
			alert("请选择一种语言");
			return false;
		}

		if(document.getElementById("code").value.length==0)
		{
			alert("代码不能为空");
			return false;
		}
		document.getElementById("code").value = document.getElementById("code").value
													.replace(/&/g, "&amp;")
													.replace(/</g, "&lt;")
													.replace(/>/g,'&gt;');

		oEditor.FCKUndo.SaveUndoStep() ;

		//dp.SyntaxHighlighter.ClipboardSwf = SCRIPT_PATH + 'clipboard.swf';
		var result = dp.SyntaxHighlighter.HighlightAll('code',1,0,0,1,0);
		var str = "";
		for(key in result)
		{
			str += "<" + usingTag + " contentEditable='false' class='dp-highlighter'>";
			str += result[key][0];
			str += "</" + usingTag + ">";
			str += "<" + usingTag + " contentEditable='false' class='";
			str += result[key][2];
			str += "' style='display:none'><pre>";
			str += result[key][1];
			str += "</pre></" + usingTag + ">";
		}
		FCKHighLighter.Add( str ) ;
		return true ;
	}

	function createScript( type )
	{
		var oScript = document.createElement("script");
		var src = TypeMapper[type];
		oScript.LANGUAGE  = "javascript";
		oScript.TYPE = "text/javascript";
		oScript.src = SCRIPT_PATH + src;
		document.body.appendChild( oScript );
	}

	function setCodeType( codeType )
	{
		document.getElementById("code").className = codeType;
		createScript(codeType);
	}

	var eSelected = oEditor.FCKSelection.GetSelectedElement() ;

	function LoadSelected()
	{
		if ( !eSelected )
			return ;

		if ( eSelected.tagName == usingTag && eSelected.className == usingFlag )
		{
			var srcNode = null;
			if (FCKBrowserInfo.IsIE) {
				srcNode = eSelected.firstChild.nextSibling;
			} else {
				srcNode = eSelected.getElementsByTagName('div').item(2);
			}

			var language    = srcNode.className;
			var codeTypeNum = document.getElementById("codeType").options.length;
			document.getElementById("code").className = language;
			createScript(language);
			for(var i=0;i<codeTypeNum;i++)
			{
				if(document.getElementById("codeType").options[i].value == language)
				{
					document.getElementById("codeType").options[i].selected = true;
				}
			}
			var codeContent = srcNode.innerHTML;

			var startInt, endInt;
			if (FCKBrowserInfo.IsIE) {
				startInt = 5;
				endInt = 6;
			} else {
				startInt = 6;
				endInt = 7;
			}

			document.getElementById('code').value = codeContent
				.substring( startInt, codeContent.length - endInt )
				.replace(/&gt;/g,'>')
				.replace(/&lt;/g, "<")
				.replace(/&amp;/g, "&");
		}
		else eSelected == null ;
	}

	function codingKeyDown( event, obj ) {
		// Process Tab key
		var tabKeyCode = 9;

		var keycode = event.keyCode;
		if (keycode == tabKeyCode) {
			if (obj.setSelectionRange) {
				// mozilla
				var s = obj.selectionStart;
				var e = obj.selectionEnd;
				obj.value = obj.value.substring(0, s) + "\t" + obj.value.substr(e);
				obj.setSelectionRange(s + 1, s + 1);
				obj.focus();
			} else if (obj.createTextRange) {
				// ie
				document.selection.createRange().text="\t"
				event.returnValue = false;
			} else {
				// unsupported browsers
			}

			if (event.preventDefault) // dom
			event.preventDefault();
			return false; // should work in all browsers
		}

		// Process Ctrl+A key for select all code
		if ( event.ctrlKey && event.keyCode == 65 || event.keyCode == 97 ) {
			document.getElementById("code").select();
			return;
		}
	}
	</SCRIPT>
</HEAD>

<BODY SCROLL="no" style="OVERFLOW: hidden">
<TABLE width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<TR><TD>
<TABLE align="center" border="0" cellpadding="0" cellspacing="5">
<FORM>
  <TR>
    <TD width="30"><SPAN FCKLANG="DlgSyntaxHighLighterSelectLang">语言</SPAN></TD>
    <TD><SELECT name="codeType" id="codeType" onChange="setCodeType(this.value);">
      <OPTION value="" FCKLANG="DlgSyntaxHighLighterSelectLang">语言</OPTION>
      <OPTION value="cpp">C++</OPTION>
      <OPTION value="c#">C#</OPTION>
      <OPTION value="css">CSS</OPTION>
      <OPTION value="delphi">Delphi</OPTION>
      <OPTION value="java">Java</OPTION>
      <OPTION value="javascript">JavaScript</OPTION>
      <OPTION value="php">PHP</OPTION>
      <OPTION value="python">Python</OPTION>
      <OPTION value="ruby">Ruby</OPTION>
      <OPTION value="sql">SQL</OPTION>
      <OPTION value="xml">XML</OPTION>
      <OPTION value="vb">VB</OPTION>
    </SELECT></TD>
  </TR>
  <TR>
    <TD><SPAN FCKLANG="DlgSyntaxHighLighterCoding">代码</SPAN></TD>
    <TD><TEXTAREA name="code" cols="" rows="" wrap="off" class="" id="code" style="width:530; height:370;" onkeydown="codingKeyDown(event, this);"></TEXTAREA></TD>
  </TR>
</FORM>
</TABLE>
</TD></TR></TABLE>
</BODY>
</HTML>
